package informationextraction;

import java.util.ArrayList;
import java.util.List;

import xmlcommandset.ComponentID;
import xmlparser.XMLInformationListener;
import xmlparser.XMLParser.ContentContext;

public class ComponentIDExtraction {
	XMLInformationListener xml_info = new XMLInformationListener();
	ComponentID comp_id = new ComponentID();

	public ComponentIDExtraction(XMLInformationListener xml_info) {
		this.xml_info = xml_info;
	}

	public XMLInformationListener getXml_info() {
		return xml_info;
	}

	public void setXml_info(XMLInformationListener xml_info) {
		this.xml_info = xml_info;
	}

	public ComponentID getComponentID() {
		return comp_id;
	}

	public void setComponentID(ComponentID list_use_permission) {
		this.comp_id = list_use_permission;
	}

	public void setComponentID() {
		List<ContentContext> list_content = xml_info.getList_content();
		String full = null;
		for (int i = 0; i < list_content.size(); i++) {
			if (list_content.get(i).getRuleContext().getText()
					.contains("uses-sdk")
					|| list_content.get(i).getRuleContext().getText()
							.contains("uses-permission")) {
				list_content.remove(i);
			}
		}
		for (int i = 0; i < list_content.size(); i++) {
//			if (list_content.get(i).getRuleContext().getText()
//					.contains("uses-sdk")
//					|| list_content.get(i).getRuleContext().getText()
//							.contains("uses-permission")) {
//				list_content.remove(i);
//			}
			
		
			if(list_content.get(i).getRuleContext().getText()
					.contains("activityandroid:name"))
			 full = (String)list_content.get(i).element(0).attribute(0).getRuleContext().getText();
			
			comp_id.setId_name(getComponentIDName(full));
			
		}

	}
	
	public String getComponentIDName(String str) {
		// TODO Auto-generated method stub
		int index = str.indexOf("=");
		String name = str.substring(index);
		if(name.contains("\""))
			return name.substring(2,name.length()-1);
		return name;
	}
}
